#include <iostream>
#include <unordered_map>
#include <algorithm>
using namespace std;

typedef long long LL;
const int N = 1e5 + 10;
int n;
LL a[N];
unordered_map<int, int> mp;
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) 
    {
        cin >> a[i];
        mp[a[i]]++;
    }
    if(mp.size() == 1) 
    {
        cout << 0 << endl;
        return 0;
    }
    else if(!mp.count(0))
    {
        cout << -1 << endl;
        return 0;
    }    
    else
    {
        sort(a + 1, a + 1 + n);
        LL cnt = 0;
        LL add = 0;
        // a[1] = 0
        for(int i = 1; i <= n; i++)
        {
            if(a[i] == 0 || a[i] == a[i - 1]) continue;
            cnt += a[i] - a[i - 1] - 1;
        }
        cout << cnt + 1 << endl;
    }
    return 0;
}
// 8
// 0 0 3 4 5 8 10 11 12 15